home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / VideoFolder 1.0a / Source / MoreFiles 1.4.1 / DirectoryCopy.p < prev    next >
Text File  |  1995-12-21  |  7KB  |  166 lines

  1. UNIT DirectoryCopy;
  2.  
  3. {    Apple Macintosh Developer Technical Support                                }
  4. {                                                                            }
  5. {    DirectoryCopy: A robust, general purpose directory copy routine.        }
  6. {    by Jim Luther, Apple Developer Technical Support Emeritus                }
  7. {                                                                            }
  8. {    File:        DirectoryCopy.p                                                }
  9. {                                                                            }
  10. {    Copyright © 1992-1995 Apple Computer, Inc.                                }
  11. {    All rights reserved.                                                    }
  12. {                                                                            }
  13. {    You may incorporate this sample code into your applications without        }
  14. {    restriction, though the sample code has been provided "AS IS" and the    }
  15. {    responsibility for its operation is 100% yours.  However, what you are    }
  16. {    not permitted to do is to redistribute the source as "DSC Sample Code"    }
  17. {    after having made changes. If you're going to re-distribute the source,    }
  18. {    we require that you make it clear in the source that the code was        }
  19. {    descended from Apple Sample Code, but that you've made changes.            }
  20.  
  21.  
  22. INTERFACE
  23.  
  24. USES
  25.     Files;
  26.  
  27. {***************************************************************************}
  28.  
  29.     { DirectoryCopy failedOperation codes. }
  30.     CONST
  31.         getNextItemOp = 1;            { couldn't access items in this }
  32.                                     { directory - no access privileges }
  33.         copyDirCommentOp = 2;        { couldn't copy directory's Finder }
  34.                                     { comment }
  35.         copyDirAccessPrivsOp = 3;    { couldn't copy directory's AFP access }
  36.                                     { privileges }
  37.         copyDirFMAttributesOp = 4;    { couldn't copy directory's File }
  38.                                     { Manager attributes }
  39.         dirCreateOp = 5;            { couldn't create destination directory }
  40.         fileCopyOp = 6;                { couldn't copy file }
  41.  
  42.  
  43. {***************************************************************************}
  44.  
  45.     TYPE
  46.         CopyErrProcPtr = ProcPtr;
  47.  
  48. {    A DirectoryCopy CopyErrProc function should have the following form:    }
  49. {                                                                            }
  50. {    FUNCTION MyCopyErrProc (error: OSErr;                                     }
  51. {                            failedOperation: Integer;                        }
  52. {                            srcVRefNum: Integer;                            }
  53. {                            srcDirID: LongInt;                                }
  54. {                            srcName: StringPtr;                                }
  55. {                            dstVRefNum: Integer;                            }
  56. {                            dstDirID: LongInt;                                }
  57. {                            dstName: StringPtr): Boolean;                    }
  58. {                                                                            }
  59. {    DirectoryCopy will call your CopyErrProc function if an error condition    }
  60. {    is detected sometime during the copy.  If your CopyErrProc returns        }
  61. {    true, then DirectoryCopy attempts to continue with the directory copy    }
  62. {    operation.  If your CopyErrProc returns false, then DirectoryCopy stops    }
  63. {    the directory copy operation.                                            }
  64. {                                                                            }
  65. {    error            input:    The error result code that caused CopyErrProc    }
  66. {                            to be called.                                    }
  67. {    failedOperation    input:    The operation that returned an error to            }
  68. {                            DirectoryCopy.                                    }
  69. {    srcVRefNum        input:    Source volume specification.                    }
  70. {    srcDirID        input:    Source directory ID.                            }
  71. {    srcName            input:    Source file or directory name, or nil if        }
  72. {                            srcDirID specifies the directory.                }
  73. {    dstVRefNum        input:    Destination volume specification.                }
  74. {    dstDirID        input:    Destination directory ID.                        }
  75. {    dstName            input:    Destination file or directory name, or nil if    }
  76. {                            dstDirID specifies the directory.                }
  77.  
  78.  
  79. {***************************************************************************}
  80.  
  81.  
  82.     FUNCTION DirectoryCopy (srcVRefNum: Integer;
  83.                                     srcDirID: LongInt;
  84.                                     srcName: StringPtr;
  85.                                     dstVRefNum: Integer;
  86.                                     dstDirID: LongInt;
  87.                                     dstName: StringPtr;
  88.                                     copyBufferPtr: Ptr;
  89.                                     copyBufferSize: LongInt;
  90.                                     preflight: Boolean;
  91.                                     copyErrHandler: CopyErrProcPtr): OSErr;
  92. {    Use DirectoryCopy to make a copy of a directory structure in a new        }
  93. {    location.  If copyBufferPtr <> NIL, it points to a buffer of            }
  94. {    copyBufferSize that is used to copy files data.  The larger the            }
  95. {    supplied buffer, the faster the copy.  If copyBufferPtr = NIL, then        }
  96. {    this routine allocates a buffer in the application heap. If you pass a    }
  97. {    copy buffer to this routine, make its size a multiple of 512            }
  98. {    ($200) bytes for optimum performance.                                    }
  99. {                                                                            }
  100. {    srcVRefNum        input:    Source volume specification.                    }
  101. {    srcDirID        input:    Source directory ID.                            }
  102. {    srcName            input:    Source directory name, or nil if                }
  103. {                            srcDirID specifies the directory.                }
  104. {    dstVRefNum        input:    Destination volume specification.                }
  105. {    dstDirID        input:    Destination directory ID.                        }
  106. {    dstName            input:    Destination directory name, or nil if            }
  107. {                            dstDirID specifies the directory.                }
  108. {    copyBufferPtr    input:    Points to a buffer of copyBufferSize that        }
  109. {                            is used the i/o buffer for the copy or            }
  110. {                            nil if you want DirectoryCopy to allocate its    }
  111. {                            own buffer in the application heap.                }
  112. {    copyBufferSize    input:    The size of the buffer pointed to                }
  113. {                            by copyBufferPtr.                                }
  114. {    preflight        input:    If true, DirectoryCopy makes sure there are        }
  115. {                            enough allocation blocks on the destination        }
  116. {                            volume to hold the directory's files before        }
  117. {                            starting the copy.                                }
  118. {    copyErrHandler    input:    A pointer to the routine you want called if an    }
  119. {                            error condition is detected during the copy, or    }
  120. {                            nil if you don't want to handle error            }
  121. {                            conditions. Error handling is recommended...    }
  122.  
  123.  
  124. {***************************************************************************}
  125.  
  126.  
  127.     FUNCTION FSpDirectoryCopy ({CONST}VAR srcSpec: FSSpec;
  128.                                     {CONST}VAR dstSpec: FSSpec;
  129.                                     copyBufferPtr: Ptr;
  130.                                     copyBufferSize: LongInt;
  131.                                     preflight: Boolean;
  132.                                     copyErrHandler: CopyErrProcPtr): OSErr;
  133. {    Use FSpDirectoryCopy to make a copy of a directory structure in a new    }
  134. {    location.  If copyBufferPtr <> NIL, it points to a buffer of            }
  135. {    copyBufferSize that is used to copy files data.  The larger the            }
  136. {    supplied buffer, the faster the copy.  If copyBufferPtr = NIL, then        }
  137. {    this routine allocates a buffer in the application heap. If you pass a    }
  138. {    copy buffer to this routine, make its size a multiple of 512            }
  139. {    ($200) bytes for optimum performance.                                    }
  140. {                                                                            }
  141. {    srcSpec            input:    An FSSpec record specifying the directory to    }
  142. {                            copy.                                            }
  143. {    dstSpec            input:    An FSSpec record specifying destination            }
  144. {                            directory of the copy.                            }
  145. {    copyBufferPtr    input:    Points to a buffer of copyBufferSize that        }
  146. {                            is used the i/o buffer for the copy or            }
  147. {                            nil if you want DirectoryCopy to allocate its    }
  148. {                            own buffer in the application heap.                }
  149. {    copyBufferSize    input:    The size of the buffer pointed to                }
  150. {                            by copyBufferPtr.                                }
  151. {    preflight        input:    If true, FSpDirectoryCopy makes sure there are    }
  152. {                            enough allocation blocks on the destination        }
  153. {                            volume to hold the directory's files before        }
  154. {                            starting the copy.                                }
  155. {    copyErrHandler    input:    A pointer to the routine you want called if an    }
  156. {                            error condition is detected during the copy, or    }
  157. {                            nil if you don't want to handle error            }
  158. {                            conditions. Error handling is recommended...    }
  159.  
  160.  
  161. {***************************************************************************}
  162.  
  163.  
  164. IMPLEMENTATION
  165.  
  166. END.